//
//  ZLCMainViewController.swift
//  ZLCWeiBo
//
//  Created by ZLC on 15/10/27.
//  Copyright © 2015年 张灵聪. All rights reserved.
//

import UIKit

class ZLCMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        tabBar.tintColor = UIColor.orangeColor()
        
        let HomeVc = ZLCHomeTableViewController()
        addChildViewController(HomeVc, title: "首页", imageName: "tabbar_home")
        
        let messageVc = ZLCMessageTableViewController()
       addChildViewController(messageVc, title:"信息", imageName: "tabbar_message_center")
        let controller = UIViewController()
        addChildViewController(controller, title: "", imageName: "f")
        
        
        let discoverVc = ZLCDiscoverTableViewController()
        addChildViewController(discoverVc, title:"发现", imageName: "tabbar_discover")
        
        let meVc = ZLCMeTableViewController()
        addChildViewController(meVc, title:"我", imageName: "tabbar_profile")
        
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        let width = tabBar.bounds.width / CGFloat(5)
        composeButton.frame = CGRect(x: width * 2, y: 0, width: width, height: tabBar.bounds.height)
        tabBar.addSubview(composeButton)
    }
    
    
    
    private func addChildViewController(controller: UIViewController, title: String,
        imageName: String) {
        
            controller.title = title
            controller.tabBarItem.image = UIImage(named:imageName)
            addChildViewController(UINavigationController(rootViewController: controller))
            
    }
    
    lazy var composeButton: UIButton = {
        let button = UIButton()
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState:UIControlState.Normal)
        button.setImage(UIImage(named:  "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        
        
        return button
    }()

   

}
